package com.lk.spring.boot.sample.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lk.spring.boot.sample.mapper.user.UserInfo;
import com.lk.spring.boot.sample.service.UserInfoService;


@RestController  //返回json字符串的数据，直接可以编写RESTFul的接口；
public class HelloController {

	@Autowired
	private UserInfoService userInfoService;
	@RequestMapping({"/","/hello"})
	public String hello(){
		return "hello,你好，这是一个spring boot应用";
	}
	
	@RequestMapping("/index")
	public String index(){
		return "hello world";
	}
	/**
	 * 返回全局异常处理 ExeptionHandler
	 * @return
	 */
	@RequestMapping("/zeroException")
    public int zeroException(){
       return 100/0;
    }
	@RequestMapping("/queryall")
	public List<UserInfo> queryAll(){
		return userInfoService.queryAll();
	}
	@RequestMapping("/{id}/getuser")
	public Map<String,Object> getUser(@PathVariable("id") int id){
		Map<String,Object> map=new HashMap<String, Object>();
		
		map.put("user", userInfoService.getByKey(id));
		return map;
	}
}
